package com.ruoyi.people.search.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.people.search.domain.UserSearch;
import com.ruoyi.people.search.service.IUserSearchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户搜索列表Controller
 * 
 * @author yjy
 * @date 2025-06-07
 */
@RestController
@RequestMapping("/search/search")
public class UserSearchController extends BaseController
{
    @Autowired
    private IUserSearchService userSearchService;

    /**
     * 查询用户搜索列表列表
     */
    @PreAuthorize("@ss.hasPermi('search:search:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserSearch userSearch)
    {
        startPage();
        List<UserSearch> list = userSearchService.selectUserSearchList(userSearch);
        return getDataTable(list);
    }

    /**
     * 导出用户搜索列表列表
     */
    @PreAuthorize("@ss.hasPermi('search:search:export')")
    @Log(title = "用户搜索列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserSearch userSearch)
    {
        List<UserSearch> list = userSearchService.selectUserSearchList(userSearch);
        ExcelUtil<UserSearch> util = new ExcelUtil<UserSearch>(UserSearch.class);
        util.exportExcel(response, list, "用户搜索列表数据");
    }

    /**
     * 获取用户搜索列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('search:search:query')")
    @GetMapping(value = "/{searchId}")
    public AjaxResult getInfo(@PathVariable("searchId") Long searchId)
    {
        return success(userSearchService.selectUserSearchBySearchId(searchId));
    }

    /**
     * 新增用户搜索列表
     */
    @PreAuthorize("@ss.hasPermi('search:search:add')")
    @Log(title = "用户搜索列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserSearch userSearch)
    {
        return toAjax(userSearchService.insertUserSearch(userSearch));
    }

    /**
     * 修改用户搜索列表
     */
    @PreAuthorize("@ss.hasPermi('search:search:edit')")
    @Log(title = "用户搜索列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserSearch userSearch)
    {
        return toAjax(userSearchService.updateUserSearch(userSearch));
    }

    /**
     * 删除用户搜索列表
     */
    @PreAuthorize("@ss.hasPermi('search:search:remove')")
    @Log(title = "用户搜索列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{searchIds}")
    public AjaxResult remove(@PathVariable Long[] searchIds)
    {
        return toAjax(userSearchService.deleteUserSearchBySearchIds(searchIds));
    }
}
